<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use EasyWeChat\Foundation\Application;
class OauthController extends Controller
{
    //微信授权
    public function index(Request $request)
    {
        $redirect_uri = $request->input('redirect_uri');
        if(empty($redirect_uri)){
            return $this->response_error(ErrorCode::ERROR_PARAM,'redirect_uri 参数不能为空');
        }
        $wechat_config = config('wechat');
            //$url = 'http://www.xxx.com/user/login?url=http://www.xxx.com/index';
        $redirect_uri = 'http://' . $_SERVER["HTTP_HOST"].$wechat_config['oauth']['callback'] . urlencode($redirect_uri);
        $appid        = $wechat_config['app_id'];

        $url = $wechat_config['weixin_snsapi']['authorize_url'] . '?appid=' . $appid;
        $url .= '&redirect_uri=' . urlencode($redirect_uri);
        $url .= '&response_type=code&scope=' . $wechat_config['weixin_snsapi']['scope_base'];
        $url .= '&state=' . $wechat_config['weixin_snsapi']['scope_base'];
        $url .= '#wechat_redirect';
        return redirect($url);
    }

}
